package com.yc.system.dto.esmodel;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.yc.framework.config.CustomFloatDeserializer;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.io.Serializable;
import java.util.Date;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Document(indexName = "bookinfo") //索引名称必须小写
public class BookInfo implements Serializable {
    //    type = FieldType.Text 默认开启分词 ； keyword - 不分词
    //    @Field(index=true,store=true,analyzer="ik_max_word",searchAnalyzer="ik_max_word",type=FieldType.Text)
    //    @Transient:默认情况下，在存储或检索文档时，所有字段都映射到文档，此注释不包括字段。
    @Id
    private long bookId;

    @Transient
    @Value("1")
    private long pageNum;
    @Value("10")
    private long pageSize;

    @Field(type = FieldType.Text,store=true,analyzer="ik_max_word",searchAnalyzer="ik_max_word")
    private String bookName;

    @Field(type = FieldType.Keyword)
    private String publisher;

    @Field(type = FieldType.Keyword)
    private String author;

    @Field(type = FieldType.Float,index = false)
    @JsonDeserialize(using = CustomFloatDeserializer.class)
    private Float fPrice; //原价

    @Field(type = FieldType.Float,index = false)
    @JsonDeserialize(using = CustomFloatDeserializer.class)
    private Float nPrice;  //标价

    @Field(type = FieldType.Float,index = false)
    @JsonDeserialize(using = CustomFloatDeserializer.class)
    private Float discount; //折扣

    @Field(type = FieldType.Float,index = false)
    @JsonDeserialize(using = CustomFloatDeserializer.class)
    private Float price;  //单价

    @Field(type = FieldType.Integer)
    private Integer depreciation;   //折损

    @Field(index = false, store = true,type=FieldType.Date,pattern="yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date pubDate;        // 出版日期

    @Field(type = FieldType.Keyword)
    private String keyword;

    @Field(type = FieldType.Keyword,index = false)
    private String coverPhoto;

    @Field(type = FieldType.Keyword)
    private String isbn;

    @Field(type = FieldType.Text,index = false)
    private String brief;  //简介

    @Field(type = FieldType.Integer)
    private Integer quantity; //库存 //批量

    @Field(type = FieldType.Integer)
    private Integer sellNum;

    @Field(type = FieldType.Integer)
    private Integer likeNum;

    @Field(type = FieldType.Integer)
    private Integer bookStatus;  //图书状态   1普通用户 售卖； 5 swiper ；2售完，3预定

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Field(index = false, store = true,type=FieldType.Date,pattern="yyyy-MM-dd HH:mm:ss")
    private Date addedTime;    //新发布

    @Field(type = FieldType.Integer)
    private Integer typeId;

    @Field(type = FieldType.Keyword)
    private String typeName;

    @Field(type = FieldType.Integer)
    private Integer pId;

    @Field(type = FieldType.Integer,index = false)
    private Integer userId; //发布者

    @Field(type = FieldType.Keyword)
    private String issuerName;

    //typeName,pId,issuerName,price
}
